home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Quick Edit ƒ
/
Subject Glossary
/
OOP
< prev
next >
Wrap
Text File
|
1998-01-13
|
17KB
|
403 lines
\ 14Jan96 DBH
CLASS DEFINITION
:CLASS -- : name super{ cname1 cname2 } opt
Begins definition of a new class. One or more classnames can be
designated as superclass(es). There are optional parameters that may
also be declared after the superclass list, including n INDEXED, LARGE,
and GENERAL.
;CLASS -- Ends definition of a class.
SUPER{ -- : cname1 cname2 } opt
Used to declare the superclass(es) when defining a class. See :class.
SUPER> ( -- : classname ) Oop Class
Used in a class definition with multiple inheritiance.
Usage is: msg: super> someSuper. someSuper is the name of
a superclass. Will assure that the named method of the
named superclass will be used rather than that from the
default left to right class search order. Replaces
supers_to_skip syntax.
TEMP ( -- ) Oop Class
ALternate syntax for TEMP{.
TEMP{ ( -- ) Oop Class
Used within a definition or local section.
Declares a temporary object list. Subsequently instantiated objects
in the list will exist only within the definition. They also get a
release: message automatically when the definition exits (either at the
semicolon or via EXIT). If you call a definition recursively, you will
get a fresh copy of any temporary objects. Example syntax is:
: SomeWord
temp{ int anInt
var aVar
string aString }
Optionally one can use TEMP { ... }.
GENERAL --
Obsolete. Do not use.
Optional class declaration that will allow late binding when this class
is used as an ivar. But note that GENERAL classes may not be used to
map ivars to Mac toolbox calls because the class header information will
be included. INDEXED classes are automatically GENERAL.
LARGE --
Sets the "large" option on an indexed class, allowing the number of
elements to be greater than 32K.
INDEXED n --
Sets a class and its subclasses to indexed, of element byte width n.
Used after the superclass declaration list when defining a new class.
Note that when instantiating an indexed class, you MUST precede the
instance name with the number of elements you wish that instance to
have. Also note that all indexed classes are automatically declared to
be GENERAL, so you may not used indexed classes to map into toolbox
calls. Also, n must be < 32K (see LARGE).
:M -- : name:
Begins definition of a method within a class. Note that name: MUST end
with a colon (:).
;M -- Ends definition of a method in a class.
PRIVATE --
Use within a class definition. Makes the following methods private—that
is, they will be accessible from within this class or any of its
subclasses, but not from anywhere else. The criterion is simply that a
call to Self of Super may access a private method, but nothing else can.
Note that for this reason you can't late-bind to a private method, even
if you do it from within the class itself.
PUBLIC --
Applies to ivars and/or methods.
Makes the following methods public—that is, they will be accessible from
anywhere. PRIVATE and PUBLIC may be used any number of times within the
one class definition. Methods are initially public when a class
compilation starts.
Also, ivars can be accessed from outside the class. They're declared this way:
class myClass super{ mySuper }
public
var aVar
int anInt
end_public
var anotherVar
int anotherInt
They're accessed from outside the class via this syntax:
msg: ivar> anIvar IN someObject
(where someObject is an object of myClass, of course).
END_PUBLIC ( -- ) OOP Class
Delimits end of a PUBLIC ivar list. See PUBLIC.
RECORD{ ( -- ) Toolbox Class
Alternate syntax for RECORD, but you cannot name the record.
RECORD ( -- : name ) Toolbox Class
The name is optional
Used in a class ivar list declaration. Subsequently declared ivars
can be used to map into a Mac toolbox record because object header
information will not be there. Note that you can not late bind to
an ivar in a RECORD{ list. See also RECORD{. Usage is as follows:
record <name> \ The name is optional
{ var v1
int i1
}
string s
CLASS_AS> ( -- : classname ) OOP Class
Mops allows you a shortcut way of sending a message to an object whose address is
on the stack at run time, but with early binding. You can do this with an objPtr, but it's also
possible to say simply
<obj addr on stack> msg: someClass
in which case an early bind is compiled to the addressed object, ASSUMED to be of the class
"someClass". For those who do sometimes give their classes less than ideal names, there's now a new syntax
for the above operation:
<obj addr on stack> msg: class_as> someClass
The old way will still work - I don't plan to delete it and maybe break existing code - but the new
way reads less ambiguously (and compiles exactly the same code).
IN_CLASS ( -- : classname ) OOP Class
If you combine the PUBLIC and STATIC ivar features, you can
get a "public static" ivar. To access this from outside the
class, you can't use the IVAR> syntax since there's no object
to refer to. So the syntax is:
msg: ivar> aStaticIvar IN_CLASS myClass
IN ( -- : objectname ) OOP DebugMOD.txt
Used to access a public ivar from outside the class.
Usage is as follows:
msg: ivar> anIvar IN someObject
(where someObject is an object of myClass, of course).
See PUBLIC.
IVAR> ( -- : ivarname ) OOP Class
Used to access a public ivar from outside the class.
Usage is as follows:
msg: ivar> anIvar IN someObject
(where someObject is an object of myClass, of course).
See PUBLIC.
END_PUBLIC ( -- ) OOP Class
Delimits end of a PUBLIC ivar list. See PUBLIC.
STATIC ( -- ) OOP Class
These are like static class variables in C++ - they belong to the class,
not the object, and thus are shared by all objects of the class.
Or you can use static{ ... } if you prefer.
The syntax for accessing them is just the same as for normal ivars.
They're declared like this:
class myClass super{ mySuper }
var oneVar
static
{ var someVar
int someInt
}
var anotherVar
In this example, someVar and someInt are static, oneVar and anotherVar are normal ivars. In the
methods of myClass, whenever you access someVar, you are accessing the SAME ivar, no matter what
object you are in, and similarly for someInt.
STATIC{ ( -- ) OOP Class
Synonym for STATIC.
CallFirst -- : methodname:
The next method definition will always execute the method indicated by
methodname: BEFORE it is executed by a subclass. Provides a way for
superclasses to limit the extent to which subclasses may override a
method.
CallLast -- : methodname:
The next method definition will always execute the method indicated by
methodname: AFTER it is executed by a subclass. Provides a way for
superclasses to limit the extent to which subclasses may override a
method.
SELF -- obj
Object reference to self. Only used in a class definition. SELF is not
necessarily the same as ^BASE, because of multiple inheritance.
SUPER -- obj
Use within a class method definition to refer to self, an instance of
the class, but the superclass method will be invoked.
LATE BINDING
[ --
Begins an expression with a late bound message that computes the address
of the object to recieve the message. e.g. get: [ 0 at: anArray ] .
This is an alternative syntax to that provided by **, [], and [self].
] -- See above.
note that [SELF], [], and ** are all synonyms.
[SELF] obj selid --
Late binds whatever is on the stack to the given method. e.g. obj
get: [self] . You must be sure that obj really does point to an
object.
[] ^obj selid -- See above.
** ^obj selid -- See above.
STANDARD METHODS
CLASSINIT: --
Our standard constructor method. The default message that is ALWAYS
sent to an object at time of instantiation, even ivars. Note that if
parameters are to be included for a classinit: for an INDEXED class, the
#elements must precede those parameters (#elems must be top item on
stack) at instantiation time (read that again). Note that for class
object classinit: is a null method, that is it does nothing.
ADDR: -- ^base
Returns the address of the beginning of an object's ivars.
CLASS: -- class Returns the class pointer for an object.
COPYTO: obj --
Copies the ivar part of the passed in object to self. Doesn't check
type - be careful.
DUMP: -- Performs a formatted dump of a class.
LENGTH: -- len
Gets total length of object. Length will include class header
information only if class is of type GENERAL. Otherwise, length is
merely the length of the ivar data field(s).
PRINT: -- Use to display a class, default is just a DUMP:.
RELEASE: --
Our standard destructor method. Any objects that allocate heap storage
will redefine this appropriately. Our convention is that an object will
release ALL its storage when it gets a release: message. Other methods
can be provided to partly release storage, as needed.
CONSOLE INSPECTION
.CLASS: -- A method. Prints the name of the class of the given object.
.ID: -- A method. Prints the name of the given object, if it has a name.
MISCELLANEOUS
BYTES n -- : ivarname
Bytes is used as the ivar allocation primitive for basic classes.
Allocates n bytes as a named instance variable of an object. You can
use bytes to map a Toolbox data structure as an object when named access
to some of the fields is not needed (but you must know the proper
length).
BIND_WITH obj --<selector> obj-modified cfa
If you are late-binding in a loop, it can be much faster if you do the
bind just once, then reuse the resulting cfa each time in the loop.
This way you only have to perform the method search once. To bind
initially and get the cfa, use BIND_WITH. Usage: (saveCfa and ^obj-mod
are values or locals). (get object's address) bind_with someSelector:
-> saveCfa -> ^obj-mod. (in the loop) ^obj-mod saveCfa ex-method.
SET_CLASS obj theClass --
SET_CLASS is a utility word used to patch nucleus objects when their
classes are defined in higher-level files. Actually it could be used to
change the class of any object, if anyone is silly enough to want to do
that.
SET_TO_CLASS objPtr -- : cname
If you need to declare the object pointer before the class exists, use
SET_TO_CLASS once the class is defined, thus: ' someOP set_to_class
someClass.
STANDARD CLASSES
(COL) -- : name
Collections are ordered lists with a current size. We implement them by
multiply inheriting the generic (COL) class with the array class of the
appropriate width. We use a few tricks to avoid late binding to self in
loops.
ARRAY #elems -- : name
The basic 4-byte cell one-dimension array. Class is INDEXED.
BOOL -- : name
Subclass of byte. Note that since the datalength of aMops class bool is
1, this class should be used to map into a Toolbox record of type
BOOLEAN.
BYTE -- : name A standard 1-byte variable class.
DICADDR -- : name
DICADDR is a relocatable dictionary address class - use to store
non-executable dictionary addresses.
HANDLE -- : name The standard class for handles.
HANDLEARRAY #elems -- : name
HANDLEARRAY and HANDLELIST are for the implementation of collections of
heap-based objects. HandleArray has normal array properties. Use
HandleList if the number of elements may grow arbitrarily large, and if
indexing isn't so important. HandleArray also includes methods to allow
the array to be used as a stack - needed for FileList.
HANDLELIST #elems -- : name
HANDLELIST allows the implementation of a list of heap-based objects.
Unlike HANDLEARRAY, the list can be of indefinite length. We use a heap
block to store the handles to the objects contiguously, rather than have
a separate block for each handle and link them together. This saves on
memory overhead and reduces the number of memory manager calls. It also
reflects the assumption that insertions and deletions into the middle of
the list will be infrequent, as these could be more inefficient than
with a linked scheme. We expect that elements will normally be added to
the end, and probably not removed at all, or not very often.
INDEXED-OBJ -- : name
Class INDEXED-OBJ is the generic superclass for all arrays. Here we
define the general indexed methods, which apply regardless of indexed
width.
LONGWORD -- : name Generic superclass for var, handle etc.
OBJHANDLE -- : name
An OBJHANDLE is a handle that points to an object in the heap.
OBJPTR -- : name
An object pointer is a "low-level" entity, rather like a value. The
syntax for object pointers is: objPtr anObjptr class_is theClass
OBJ_ARRAY #elems -- : name
OBJ_ARRAY is a generic superclass which makes it easy to generate an
array of objects of a given class. Just define a new class which
multiply inherits from the given class (or classes) and OBJ_ARRAY (which
must come last). This will add an indexed section to each object of the
new class, with elements wide enough to contain objects of the original
class. Then SELECT: "switches in" the selected element to be the
"current" element, and all the normal methods of the class can then be
used. Note the use of"32767 indexed" in the class definition.
ORDERED-COL #elems -- : name
Ordered-Collection is a collection of 4-byte cells. A subclass of (col)
and array.
PTR -- : name A standard class. For toolbox pointers.
RESOURCE -- : name
Provides basic support for Toolbox resources.
SEQUENCE #elems -- j : name
A generic superclass for classes which have multiple items which
frequently need to be looked at in sequence. At present the main
function of Sequence is to implement the EACH: method, which makes it
very simple to deal with each element. Sequence can be multiply
inherited with any class which implements the FIRST?: and NEXT?:
methods. The actual implementation details are quite irrelevant, as
long as these methods are supported.
VAR -- : name
The standard variable class. Subclass of longword that adds the +: and
-: methods. Useful as an ivar that maps into a Toolbox LONGINT record
structure.
X-ADDR -- : name
X-ADDR is an executable dictionary address class. The only significant
difference to DicAddr is that there is an Exec: method and no Get:
method. But if we ever have to separate code and data, having a
separate class could prove very useful.
X-ARRAY #elems -- : name
A subclass of ARRAY, can execute its elements (which are cfas of Mops
words).
X-COL #elems -- : name
X-COL is a collection of executable word addresses. A subclass of (col)
and x-array.
PRIMITIVES
^BASE -- addr
Addr is the base address of the private data of the object. Only used
in a class definition. Same as addr: self.
OBJ -- obj
Called from within an inline method. Passes the object's base and
displacement to Handlers to generate the correct address. Optimization
will then apply.
OBJECT -- class
The root class of all classes. Only used as a declared superclass when
defining a new class. Note that class object has the pre-defined
methods class:, .id:, .class:, addr:, length:, copyto:, classinit:,
release:, dump:, and print:. So ALL objects possess these methods.
Some of these methods do nothing, for class object.
OBJLEN -- n Computes total data length of current object.
CHKSAME obj -- obj
A check that two objects are of exactly the same class. Aborts with
error message if not.
CHKCLASS cfa -- cfa
Aborts and issues error message if the cfa does not refer to a class.
?>CLASS obj -- class
Converts the pointer to an object to a pointer to its class. Aborts if
failure.
?CLASS -- Error if not compiling a class definition.
CL1 -- Cleans up the class compiler data on an abort.
CL>LEN #els class -- #els len
Gets data length of object given #els and class.
DFA class -- dfa
Given a pointer to a class, returns the data field address. First 2
bytes are the data length, second 2 bytes are the width of the indexed
elements.
DLEN&XWID class -- dlen xwid
Given a class pointer, retuns the ivar datalength and width of the
indexed elements.
EXMID obj selID --
Executes a method given its sel ID. Used in late binding.
FFA ^class -- ffa
Given a pointer to a class, returns the flag field address.
FINDM selID class -- offs cfa Finds a method in a class.
GETDLEN obj -- n Gets length of object's named ivars.
IFA class -- ifa
Given a pointer to a class, returns the ivar field address.
IVFINDM selID ^ivar -- offs cfa Looks for a method in
IX -- ifa
Called from within an inline method. Compiles code to generate the
indexed address.
META -- class
META is the super class of Object - top of all inheritance.
MFA class -- mfa Given a pointer to a class, returns the methods field address.
RELCNT -- n
A value. For testing - counts release: msgs to make sure we're
releasing everything.
SFA class -- sfa
Given a pointer to a class, returns the superclass field address, which
is an N-way pointer.
SUPER( -- : cname1 cname2 } opt Synonym for super{.
XWID class -- xwid Given a class pointer, retuns the width of the indexed elements.
^CLASS -- class Addr of the class we're currently compiling.
^DLEN obj -- dfa Returns the dfa for the given object.
^ELEM idx -- addr Leaves addr of indexed element.